﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Slf;

namespace Logging_To_Different_Categories
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.ForegroundColor = ConsoleColor.Green;
      Console.Out.WriteLine("App.config was configured to write to two different files:\n");
      Console.Out.WriteLine("  - log-common.txt (written to by the Common category)");
      Console.Out.WriteLine("  - log-data-access.txt (written to by the DataAccess category)");
      Console.ResetColor();

      //get the common logger
      ILogger logger = LoggerService.GetLogger("Common");
      logger.Info("This info is written to the common log file.");
      
      //get the data-access logger
      logger = LoggerService.GetLogger("DataAccess");
      logger.Warn("This warning is written to the data-access log file.");

      //get an un-named logger
      logger = LoggerService.GetLogger();
      logger.Info("This info is written to the common log file because the common category is configured as the default category, which is used when the logger name does not match any of the configred categories");

      //get a logger that writes to both categories
      logger = LoggerService.GetLogger("DataAccess, Common");
      logger.Warn("This warning is also written to the both the DataAccess and Common Log");

      //get the data-access logger
      logger = LoggerService.GetLogger("DataAccess");
      logger.Debug("This debug message was not written to the data-access log file because of the level filter in the configuration");

      Console.ReadLine();
    }
  }
}
